<?php
$currencyMark = text::get('currency.mark-' . ViregWizardData::$CURRENCY_CODE);

// $jsSubmitForm = "return submitFormToUrl(this, '" . url::site('/admin/viRegistration/saveForm') . "')";

$fb = new FormBuilder('viRegistration', $optionsForm);
$fb->setFormId('wizardForm');
$fb->doNotOpenForm();
$fb->doNotCloseForm();
$fb->hidden('vi_registration_id');
// $fb->comboBox('currency_code', $currencyOptions)->noEmptyOption()->onChange($jsSubmitForm);

if ($this->getAuthUser('is_admin')) {
    $fb->yesNoBox('is_instructor')
            ->noEmptyOption()
            ->onChange($jsSubmitForm);
    $fb->decimal('course_fee')->appendix($currencyMark)->onChange($jsSubmitForm);
    $fb->decimal('extra_discount')->appendix($currencyMark)->onChange($jsSubmitForm);
    $fb->yesNoBox('is_present')->noEmptyOption();
}
else {
    $fb->display('course_fee')->value(format::decimal($optionsForm['course_fee']) . ' ' . $currencyMark);
}
$fb->write();

/* Accomodation type */
echo '<h2>' . text::getEscaped('viregWizard.accomodationTypes') . '</h2>';
echo '<p class="description">' . text::getEscaped('viregWizard.accomodationTypes-desc') . '</p>';
echo '<div>';
foreach ($viAccomodationTypeList as $accomodationType) {
    echo '<label title="' . $accomodationType['description'] . '">';
    echo form::selectOneRadio('vi_accomodation_type_code', $accomodationType['code'], $optionsForm, 'onchange="' . $jsSubmitForm . '"');
    echo $accomodationType['name'];
    $accomodationPrice = format::decimal(bcmul($optionsForm['night_count'], $accomodationType['price_' . ViregWizardData::$CURRENCY_CODE], sql::$DECIMAL_PRECISION)) . ' ' . $currencyMark;
    if ($optionsForm['vi_accomodation_type_code'] == $accomodationType['code']) {
        echo ' <span class="registrationPrice">' . $accomodationPrice . '</span>';
    }
    else {
        echo ' (' . $accomodationPrice . ')';
    }
    echo '</label><br/>';
}
echo '<hr style="width: 25em; margin-left: 0" />';
if ($this->getAuthUser('is_admin')) {
    echo '<label>' . text::getEscaped('viRegistration.night_count') . ':' . form::integer('night_count', $optionsForm['night_count'], 'onchange="' . $jsSubmitForm . '"') . '</label>';
}
else {
    echo form::hidden('night_count', $optionsForm['night_count']);
    echo '<label>' . text::getEscaped('viRegistration.night_count') . ' ' . $optionsForm['night_count'] . '</label>';
}
echo '</div>';

/* Meals */
$mealsForm = new View('/user/viregWizard/fragments/mealsForm');
$mealsForm->set('jsSubmitForm', $jsSubmitForm);
$mealsForm->render(true);

/* Prices and discounts */
$socialDiscount = $viSeminar['prices-' . ViregWizardData::$CURRENCY_CODE]['social_discount'];
if ($socialDiscount || $optionsForm['early_discount']) {
	echo '<h2>' . text::getEscaped('viregWizard.discounts') . '</h2>';
	echo '<ul>';
	if ($socialDiscount) {
	    echo '<li>';
	    echo '<em>' . text::getEscaped('viregWizard.socialDiscount') . '</em><br/>';
	    echo '<p class="description">' . text::getEscaped('viregWizard.socialDiscount-desc') . '</p>';
	    echo '<p>' . text::getEscaped('viregWizard.discountHeight') . ': ' . format::decimal($viSeminar['prices-' . ViregWizardData::$CURRENCY_CODE]['social_discount']) . ' ' . $currencyMark . '</p>';
	    echo '<label>' . text::getEscaped('viregWizard.applyThisDiscount') . ':' .
	            form::yesNoComboBox('social_discount_applied', $optionsForm['social_discount_applied'], 'onchange="' . $jsSubmitForm . '"') . '</label>';
	    echo '</li>';
	}
	if ($optionsForm['early_discount']) {
		echo '<li>';
		echo '<em>' . text::getEscaped('viSeminar-early_discount') . '</em><br/>';
		echo '<p class="description">' . text::getEscaped('viSeminar-early_discount-desc') . '</p>';
		echo '<p>' . text::getEscaped('viregWizard.discountHeight') . ': <span class="registrationPrice">' . format::decimal($optionsForm['early_discount']) . ' ' . $currencyMark . '</span></p>';
		echo '</li>';
	}
	echo '</ul>';
}

/* Total price */
if ($optionsForm['total_price']) {
    echo '<h2>' . text::getEscaped('viregWizard.totalPrice') . '</h2>';
    echo '<span class="registrationPrice">' . format::decimal($optionsForm['total_price']) . ' ' . $currencyMark . '</span>';
}

// form::close();